package com.steam.xbcc.mq;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.steam.xbcc.domain.MediaFile;
import com.steam.xbcc.service.IMediaFileService;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;

@Component
@RocketMQMessageListener(
        consumerGroup = "mediafile-consumer",
        topic = "media-file-topic",
        selectorExpression = "media-push-tag",
        messageModel = MessageModel.CLUSTERING
)
public class CourseMediaVideoPushConsumer implements RocketMQListener<MessageExt> {

    @Autowired
    private IMediaFileService mediaFileService;

    @Override
    public void onMessage(MessageExt messageExt) {
        String messageFile = new String(messageExt.getBody(), StandardCharsets.UTF_8);
        MediaFile mediaFile = JSON.parseObject(messageFile, MediaFile.class);
        mediaFileService.handleFile2m3u8(mediaFile);
    }
}
